package com.situ.system.util;

import java.io.IOException;

import javax.servlet.Filter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

@WebFilter(urlPatterns = { "/web/page/*" })
public class UserFilter implements Filter {
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws ServletException, IOException {
		HttpServletRequest hs = (HttpServletRequest) request;
		Object user = hs.getSession().getAttribute("user");
		if (user == null) {
			request.getRequestDispatcher("/web/login.jsp").forward(request, response);
		} else {
			chain.doFilter(request, response);
		}
	}
}
